import 'package:flutter/material.dart';
import 'package:online_study/mine/exam/exam_bean.dart';
import 'package:online_study/theme/colors.dart';
import 'package:online_study/theme/size.dart';

//每日答题错题分析最小单位
class AnswerItemPage extends StatefulWidget {
  ExamBean _bean;

  AnswerItemPage(this._bean);

  @override
  _AnswerItemPageState createState() => _AnswerItemPageState(_bean);
}

class _AnswerItemPageState extends State<AnswerItemPage> {
  ExamBean _bean;

  _AnswerItemPageState(this._bean);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: ThemeColor.colorWhite,
      padding: EdgeInsets.symmetric(vertical: ThemeSize.height12),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildQuestion(),
          _buildImage(),
          _buildOptions(),
          _buildAnswers()
        ],
      ),
    );
  }

  Widget _buildQuestion() {
    String type = "";
    if (_bean.isMulti) {
      type = "[多选]";
    } else {
      type = "[单选]";
    }
    String question = _bean.index.toString() + "." + type + _bean.question;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.max,
      children: [
        Container(
          padding: EdgeInsets.only(
              left: ThemeSize.width19,
              right: ThemeSize.width19,
              bottom: ThemeSize.height8),
          child: Text(question,
              style: TextStyle(
                  color: ThemeColor.color333333,
                  fontSize: ThemeSize.sp13,
                  fontWeight: FontWeight.bold),
              softWrap: true),
        ),
      ],
    );
  }

  Widget _buildOptions() {
    return Column(
      children: _bean.answers
          .map((e) => Container(
                padding: EdgeInsets.only(
                    left: ThemeSize.width19,
                    right: ThemeSize.width19,
                    bottom: ThemeSize.height12),
                child: Container(
                  width: double.infinity,
                  child: Row(
                    children: [
                      Icon(
                        Icons.check_circle,
                        size: ThemeSize.height14,
                        color: Comparable.compare("D . 过度饮酒", e) > 0
                            ? ThemeColor.colorCorner
                            : ThemeColor.color1485EE,
                      ),
                      Container(
                        margin: EdgeInsets.only(left: ThemeSize.width12),
                        child: Text(
                          e,
                          style: TextStyle(
                              color: ThemeColor.color333333,
                              fontSize: ThemeSize.sp13),
                        ),
                      )
                    ],
                  ),
                ),
              ))
          .toList(),
    );
  }

  Widget _buildAnswers() {
    return Column(
      children: [
        Container(
            width: double.infinity,
            margin: EdgeInsets.only(left: ThemeSize.width19),
            child: Text(
              "正确答案:" + _bean.correctAnswers.toString(),
              style: TextStyle(
                  color: ThemeColor.color555555,
                  fontSize: ThemeSize.sp13,
                  fontWeight: FontWeight.bold),
            )),
        Container(
            margin: EdgeInsets.only(
                left: ThemeSize.width19, top: ThemeSize.height12),
            child: Text(
              "提升自身形象包括：肢体语言、着装、专业要塑造个人形象，需要做到仪表讲究、有风度有学识、有涵养，语言沟通要谦虚、文明、幽默等，从各方面进行改变有利于自己长远发展的个人形象",
              style: TextStyle(
                  color: ThemeColor.color333333, fontSize: ThemeSize.sp13),
            ))
      ],
    );
  }

  Widget _buildImage() {
    return Visibility(
        visible: true,
        child: Container(
          margin: EdgeInsets.only(
              left: ThemeSize.width19,
              right: ThemeSize.width19,
              bottom: ThemeSize.height20),
          height: ThemeSize.height126,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(ThemeSize.height8),
              image: DecorationImage(
                  image: NetworkImage(
                      "https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg"),
                  fit: BoxFit.cover)),
        ));
  }
}
